Skip to content

Handle CR without NL printed in EditorConsole #9954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

matthijskooijman
Copy link
Collaborator

When uploading a sketch using dfu-util (e.g. used by various STM32 cores), progress bar lines would be printed. However, each update would be printed on a new line, rather than overwriting the same line as intended. Even more, the console would not scroll when subsequent lines were added, which made it quite annoying to see the upload progress.

It turns out dfu-util uses lone \r to overwrite the previous line. However, EditorConsole would simply replace those with \n instead. But because ConsoleOutputStream only scrolled on \n, these extra lines would fall out of view on the bottom of the console.

I originally tried updating the scroll behaviour to include these lines, but then thought it would be even nicer to just properly handle \r characters instead. That took a bit more time than I had anticipated, but the result is fairly clean code, I think :-)

With this PR applied, the dfu-util now looks like this:

Peek 2020-03-28 15-14

Without this PR, it was like this (note that most of the action happens outside of view below, until the upload is complete):

Peek 2020-03-28 17-13

As an additional test for partial line overwriting, I added this bit of shell script to a script that was used during upload:

echo -ne 'ABCDEF\r'
sleep 3;
echo -ne 'DEF\r'
sleep 3;
echo -ne 'X\n'
sleep 3;
echo -ne 'ZZZ\n'

Which works as expected:

Peek 2020-03-28 15-13

Again, this would be a good candidate for some testcases. @cmaglie, do you have some notes you could share about how to run the testsuite in a meaningful way (especially just run a single testcase)?

@facchinm
Copy link
Member

LOVE. THIS. PR

@cmaglie
Copy link
Member

cmaglie commented Apr 27, 2020

Nice! Definitely I want to see this feature implemented!

As an additional test for partial line overwriting, I added this bit of shell script to a script that was used during upload:

I'd like to see also a test when multiple lines are sent together like:

echo -ne 'ABCDEF\rDEF\rX\nZZZ'
sleep 3;
echo -ne 'ZZZ\rYYY\n'

Again, this would be a good candidate for some testcases. @cmaglie, do you have some notes you could share about how to run the testsuite in a meaningful way (especially just run a single testcase)?

You can't run a single test from ant with the current build.xml AFAIK, I usually run them one by one from eclipse.

@cmaglie cmaglie added this to the Release 1.8.13 milestone Apr 27, 2020
@matthijskooijman
Copy link
Collaborator Author

I'd like to see also a test when multiple lines are sent together like:

Good point. I might have already tested this, but let's do this regardless.

You can't run a single test from ant with the current build.xml AFAIK, I usually run them one by one from eclipse.

Ah, I don't have eclipse set up anymore, so that's not an easy way out here :-)

@matthijskooijman
Copy link
Collaborator Author

Ok, just pushed an update. I rebased on top of master and added a fixup commit with some improvements and a testcase. Took me a bit longer than expected after I started on this two days ago, but I produced a few more PRs with test-suite fixes and repo cleanup along the way, so that's nice :-p

As far as I'm concerned, I think this is now ready to merge (after squashing the fixup commit, of course).

Not trimming makes this method usable for unittesting. Since this method
is not currently used anywhere, it should not affect any behaviour.
This allows testing this class without going to a full initialization.
…onsole

Previously, the redirection would be triggered in the EditorConsole
constructor. However, this was problematic for unittests, which do not
need this redirection.

Since the redirection really is not useful intul there is a current
EditorConsole anyway, it can just be delayed a bit until
setCurrentEditorConsole is called.
Previously, any CR without NL was treated just like a NL. For tools that
used single CRs to update a progress bar (such as dfu-util), this would
end up printing the subsequent versions of the progress bar below each
other, instead of updating a single line as intended. Additionally,
since ConsoleOutputStream only scrolled the view on \n, these updates
would end up outside of the main view, making the upload progress quite
unclear.

This commit makes EditorConsole support lone CRs by resetting the insert
position to the start of the current line, so subsequent writes
overwrite existing content. If subsequent lines are shorter than an
earlier line, only part of the earlier line will be overwritten (this
mimics what terminal emulators do).
@matthijskooijman
Copy link
Collaborator Author

Just amended some more style fixes into the fixup commit and prepended some more commits to EditorConsole to make the testcases work (I had those already, but accidentally split them into the wrong pull request :-p). So now it is ready for merging :-)

@arduino arduino deleted a comment from ArduinoBot May 7, 2020
@arduino arduino deleted a comment from ArduinoBot May 7, 2020
@arduino arduino deleted a comment from ArduinoBot May 11, 2020
@facchinm
Copy link
Member

Rebased and merged 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE The Arduino IDE Type: Bug Type: Duplicate Another item already exists for this topic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants